<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :model="model" :rules="validatorRules">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="项目号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="no">
              <a-input v-model="model.no" placeholder="请输入项目号" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="项目名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
              <a-input v-model="model.name" placeholder="请输入项目名" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="所属省份" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="province">
              <a-input v-model="model.province" placeholder="请输入所属省份" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="所属站段" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="station">
              <a-input v-model="model.station" placeholder="请输入所属站段" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="所属地市" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="city">
              <a-input v-model="model.city" placeholder="请输入所属地市" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="location">
              <a-input v-model="model.location" placeholder="请输入地址" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="建设单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="buildCompany">
              <a-input v-model="model.buildCompany" placeholder="请输入建设单位" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="建成时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="buildFinishTime">
              <j-date placeholder="请选择建成时间" v-model="model.buildFinishTime" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="房屋报建性质" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="type">
              <j-dict-select-tag type="list" v-model="model.type" dictCode="znzf_project_type,name,value" placeholder="请选择房屋报建性质" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="建筑结构" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="structure">
              <a-input v-model="model.structure" placeholder="请输入建筑结构" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="楼层数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="floorNum">
              <a-input-number v-model="model.floorNum" placeholder="请输入楼层数量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="梯口数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="elevatorNum">
              <a-input-number v-model="model.elevatorNum" placeholder="请输入梯口数量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="住房总套数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="roomNum">
              <a-input-number v-model="model.roomNum" placeholder="请输入住房总套数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="确权办证时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="confirmTime">
              <j-date placeholder="请选择确权办证时间" v-model="model.confirmTime" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备用字段2" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="temp2">
              <a-input v-model="model.temp2" placeholder="请输入备用字段2" ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </a-spin>
  </j-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: "ZnzfProjectModal",
    components: { 
    },
    data () {
      return {
        title:"操作",
        width:800,
        visible: false,
        model:{
        },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules: {
           no: [
              { required: true, message: '请输入项目号!'},
           ],
           name: [
              { required: true, message: '请输入项目名!'},
           ],
           station: [
              { required: true, message: '请输入所属站段!'},
           ],
           type: [
              { required: true, message: '请输入房屋报建性质!'},
           ],
        },
        url: {
          add: "/projectroom/znzfProject/add",
          edit: "/projectroom/znzfProject/edit",
        }
     
      }
    },
    created () {
    //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      close () {
        this.$emit('close');
        this.visible = false;
        this.$refs.form.clearValidate();
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }else{
             return false
          }
        })
      },
      handleCancel () {
        this.close()
      },

      
    }
  }
</script>